package com.hyt.it.ogt.ks.mapper;

import java.math.BigDecimal;
import java.util.List;

import com.hyt.it.ogt.ks.model.dto.CandidateAnswerSimpleVO;
import org.apache.ibatis.annotations.Param;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hyt.it.ogt.ks.api.kw.model.ObjectiveItemScoreDTO;
import com.hyt.it.ogt.ks.feign.model.SubjectiveAnswerVO;
import com.hyt.it.ogt.ks.model.entity.CandidateAnswer;
import com.hyt.it.ogt.ks.model.vo.CandidateFinishExamVO;

/**
 * <p>
 * 考试答案详情表 Mapper 接口
 * </p>
 *
 * @author chengxh
 * @since 2020-06-17
 */
public interface CandidateAnswerMapper extends BaseMapper<CandidateAnswer> {

    /**
     * 批量插入答案表数据
     *
     * @param list 参数
     * @return 插入条数
     */
    int insertAnswers(List<CandidateAnswer> list);

    /**
     * 获取考生答案信息，生成试卷小题结构使用
     *
     * @param examId      考试ID
     * @param candidateId 考生ID
     * @return 数组
     */
    List<CandidateAnswer> selectAnswerByCandidateId(String examId, String candidateId);

    /**
     * 更新考生答案
     *
     * @param candidateAnswer 答案
     * @return 更新条数
     */
    int updateAnswer(CandidateAnswer candidateAnswer);

    /**
     * 修改标记状态
     *
     * @param examId      考试ID
     * @param candidateId 考生ID
     * @param itemId      小题编号
     * @param flagState   状态
     * @return 更新条数
     */
    int updateState(String examId, String candidateId, String itemId, Integer flagState);

    /**
     * 统计每小题分数
     *
     * @param vo 参数
     * @return 更新条数
     */
    int calcObjectiveScore(CandidateFinishExamVO vo);

    /**
     * 查询考生试卷总分
     *
     * @param vo vo
     * @return 分数
     */
    BigDecimal getObjectiveScore(CandidateFinishExamVO vo);

    BigDecimal getObjectiveScoreByPaper(String examId, String candidateId, String paperId, String paperVersion);

    List<SubjectiveAnswerVO> getSubjectiveAnswerByExam(@Param("examId")String examId, @Param("admissionNumber")String admissionNumber,
                                                       @Param("commit")Integer commit);

    List<SubjectiveAnswerVO> getSubjectiveAnswerByExamWhenBackup(@Param("examId")String examId, @Param("admissionNumber")String admissionNumber,
                                                       @Param("commit")Integer commit);

    /**
     * 查询答案
     * @param examId
     * @param admissionNumber
     * @return
     */
    List<CandidateAnswer> selectAnswerList(String examId, String admissionNumber);

    /**
     * 重置考试答案
     * @param examId
     * @param candidateId
     * @param answerVer
     * @return
     */
    int redoCandidateAnswers(@Param("examId")String examId,@Param("candidateId")String candidateId,@Param("answerVer")Integer answerVer);

    /**
     * 查询最大成绩的版本号
     * @param examId
     * @param candidateId
     * @return
     */
    String selectMaxScoreAnswerVer(@Param("examId")String examId,@Param("candidateId")String candidateId);

    int countNotFinishItemNumber(String examId, String candidateId, Integer paperSort, int page);

    List<ObjectiveItemScoreDTO> getObjectiveItemScore(String examId, String candidateId,String paperId, String paperVersion);

    List<CandidateAnswerSimpleVO> selectSimpleAnswerList(@Param("examId")String examId, @Param("candidateIds") List<String> candidateIds, @Param("maxScoreVers") List<Integer> maxScoreVers);
}
